﻿using DotNetty.Buffers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DoNetDrive.AspWebSocke
{
    public static class WebSocketUnpooled
    {
        static readonly UnpooledByteBufferAllocator Allocator = UnpooledByteBufferAllocator.Default;
        public static IByteBuffer WrappedTextBuffer(string text,Encoding encoding)
        {
            byte[] buffer = encoding.GetBytes(text);
            IByteBuffer buf = new TextBuff(Allocator, buffer, buffer.Length);
            buf.SetWriterIndex(buffer.Length);
            return buf;
        }
        public static IByteBuffer WrappedTextBuffer(byte[] buffer)
        {
           // byte[] buffer = encoding.GetBytes(text);
            IByteBuffer buf = new TextBuff(Allocator, buffer, buffer.Length);
            buf.SetWriterIndex(buffer.Length);
            return buf;
        }
        public static IByteBuffer WrappedBinaryBuffer(byte[] buffer)
        {
            IByteBuffer buf = new BinaryBuff(Allocator, buffer, buffer.Length);
            buf.SetWriterIndex(buffer.Length);
            return buf;
        }
    }
}
